﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PB.Airsoft.Business.Item;
using PB.Airsoft.Business.Item.Interfaces;
using PB.Airsoft.NHibernateWrapper;
using System.Configuration;
using PB.Airsoft.Core.Unity;

namespace PB.Airsoft.Provider.NHibernate.Item
{
    public class NHibernateItemProvider : ItemProvider
    {
        private ISessionManager CreateSessionManager(bool readOnly)
        {
            return new SessionManager(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString, readOnly);
        }

        public override IItem GetItem(Guid id)
        {
            using (var sm = CreateSessionManager(true))
            {
                return (IItem)sm.Session.Get(IoC.GetRegisteredType<IItem>(), id);
            }
        }
    }
}
